﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using FRL.DebtChased.Silverlight.Library.RichContentService;


namespace FRL.DebtChased.Silverlight.Library
{
    public partial class AddNoteDlg : ChildWindow
    {
        private ObservableCollection<AccountNoteTransport> _notes;
        private AccountTransport _account;

        public AddNoteDlg(ObservableCollection<AccountNoteTransport> notes)
        {
            InitializeComponent();
            this._notes = notes;
        }

        public AddNoteDlg(AccountTransport account)
        {
            InitializeComponent();
            this._notes = account.Notes;
            this._account = account;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;

            if (_notes != null)
            {
                AccountNoteTransport note = new AccountNoteTransport();
                note.Narrative = NoteBody.Text;
                note.UserDescription = "Some User";
                note.Timestamp = DateTime.Now;
                _notes.Add(note);

                if (_account != null)
                {
                    // Call server function
                    RichContentServiceClient proxy = new RichContentServiceClient();
                    proxy.Endpoint.Address = ExtensionsForSilverlight.CreateDebtChasedEndpoint();
                    proxy.AddAccountNoteCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(proxy_AddAccountNoteCompleted);
                    proxy.AddAccountNoteAsync(_account, note);
                    note.Narrative = note.Narrative + " - code modified";
                    //proxy.KillActiveAccountPlanCompleted += new EventHandler<KillActiveAccountPlanCompletedEventArgs>(proxy_KillActiveAccountPlanCompleted);
                    //proxy.KillActiveAccountPlanAsync(
                    //    m_accountPlan.AccountPlanId,
                    //    strReason,
                    //    chkAlertManager.IsChecked ?? false
                    //);
                }
            }
        }

        void proxy_AddAccountNoteCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            string s = "new note created";
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

